package com.module.app.utils;

import android.os.Environment;

import com.module.app.base.BaseApplication;

import java.io.File;

/**
 * @author bsnl_yanxuwen
 * @date 2021/4/15 17:57
 * Description :
 */
public class FileUtils {
    private final static String FILE2 = "私人空间";//外部存储
    public final static String SKIN = "skin";//内部存储
    public final static String DB = "db";//内部存储


    /**
     * 获取sd卡路径，目前已过时，请及时更换最新的
     */
    public static File getSDPath() {
        return Environment.getExternalStorageDirectory();
    }

    /**
     * 获取SD卡 app路径
     */
    public static String getSDAppPath() {
        File appDir = new File(getSDPath(), FILE2);
        if (!appDir.exists()) {
            appDir.mkdir();
        }
        return appDir.getAbsolutePath();
    }

    /**
     * 获取app路径
     * /sdcard/Android/data/包名/files
     */
    public static File getAppPath(String name) {
        return BaseApplication.getContext().getExternalFilesDir(name);
    }

    /**
     * 获取app 临时缓存路径
     * /sdcard/Android/data/包名/cache
     */
    public static File getCachePath() {
        return BaseApplication.getContext().getExternalCacheDir();
    }

    /**
     * 获取apk下载路径
     */
    public static String getApkPath() {
        File appDir = new File(getSDAppPath(), "apk");
        if (!appDir.exists()) {
            appDir.mkdir();
        }
        return appDir.getAbsolutePath();
    }

    /**
     * 获取临时目录
     */
    public static String getTemporaryPath() {
        File appDir = new File(getSDAppPath(), "temporary");
        if (!appDir.exists()) {
            appDir.mkdir();
        }
        return appDir.getAbsolutePath();
    }

    /**
     * 获取背景图路径
     */
    public static String getBgPath() {
        File appDir = getAppPath("background");
        if (!appDir.exists()) {
            appDir.mkdir();
        }
        return appDir.getAbsolutePath();
    }

    /**
     * 获取App背景图路径
     */
    public static String getAppBgPath() {
        File appDir = new File(getBgPath(), "app");
        if (!appDir.exists()) {
            appDir.mkdir();
        }
        return appDir.getAbsolutePath();
    }



    /**
     * 获取皮肤路径
     */
    public static String getSkinPath() {
        File appDir = getAppPath(SKIN);
        if (!appDir.exists()) {
            appDir.mkdir();
        }
        return appDir.getAbsolutePath();
    }

    /**
     * 获取数据库路径
     */
    public static String getDBPath() {
        File appDir = getAppPath(DB);
        if (!appDir.exists()) {
            appDir.mkdir();
        }
        return appDir.getAbsolutePath();
    }

    /**
     * 获取getDBPath路径下文件
     * 这里不主动创建。
     */
    public static String getDBPath(String name) {
        File appDir = new File(getDBPath(), name);
        return appDir.getAbsolutePath();
    }


}
